package com.xjgc.common.utils;

import java.beans.PropertyDescriptor;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.beanutils.PropertyUtils;

import lombok.extern.slf4j.Slf4j;
@Slf4j
public class BetValUtil {

    public static Date parseDate(String dt) throws ParseException {
        Date date=new Date();
        SimpleDateFormat spt = new  SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        date = spt.parse(dt);
        return date;
    }

    public static Map<String, String> betValue( Object searchObj, Map<String, String[]> parameterMap) {
        PropertyDescriptor origDescriptors[] = PropertyUtils.getPropertyDescriptors(searchObj);
        String name,type, beginKey = null,endKey = null;
        String endValue = null,beginValue = null;
        Map<String, String> map = new HashMap<>();
        for (int i = 0; i < origDescriptors.length; i++) {
            name = origDescriptors[i].getName();
            /*type = origDescriptors[i].getPropertyType().toString();*/
            if (parameterMap != null && parameterMap.containsKey(name + "_begin")) {
                beginValue = parameterMap.get(name + "_begin")[0].trim();
                beginKey = name + "_begin";
                map.put(beginKey,beginValue);
            }
            if (parameterMap != null && parameterMap.containsKey(name + "_end")) {
                endValue = parameterMap.get(name + "_end")[0].trim();
                endKey = name + "_end";
                map.put(endKey,endValue);
            }
        }

        return map;
    }
}
